package com.cdn.nodes.api.factory;

import com.cdn.common.core.domain.R;
import com.cdn.nodes.api.RemoteClusterService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RemoteClusterFallbackFactory implements FallbackFactory<RemoteClusterService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteClusterService.class);

    @Override
    public RemoteClusterService create(Throwable throwable) {
        log.error("节点服务调用失败:{}", throwable.getMessage());
        return new RemoteClusterService()
        {
            @Override
            public R<List<Long>> getNodesByClusterId(Long cluster) {
                return R.fail("获取节点失败:" + throwable.getMessage());
            }

            @Override
            public R<String> getDnsByClusterId(Long cluster) {
                return R.fail("获取集群域名失败:" + throwable.getMessage());
            }

            @Override
            public R<String> getClusterSsh(Long cluster) {
                return R.fail("获取集群认证失败:" + throwable.getMessage());
            }
        };
    }
}
